trigger Assignment6_4_Mycount on Student__c (after delete, after insert) {
    Map<id, Class__c> clsMap = new Map<id, Class__c>([select id, My_Count__c from Class__c]);
    System.debug(logginglevel.INFO, '***** clsMap' + clsMap);
    List<Class__C> clsToBeUpdated = new List<Class__c>();
    if(Trigger.isDelete){
        for(Student__c student : Trigger.old) {
            Class__c studentClass = clsMap.get(student.Class__c);
            System.debug(logginglevel.INFO, '***** studentClass   = ' + studentClass  );
            System.debug(logginglevel.INFO, '***** student.Class__c  = ' + student.Class__c );
            System.debug(logginglevel.INFO, '***** studentClass.My_Count__c   = ' + studentClass.My_Count__c  );
            
            studentClass.My_Count__c--;
            clsToBeUpdated.add(studentClass);
        }
        
    } else { //insert 
        for(Student__c student : Trigger.new) {
            Class__c studentClass = clsMap.get(student.Class__c);
            System.debug(logginglevel.INFO, '***** studentClass   = ' + studentClass  );
            System.debug(logginglevel.INFO, '***** student.Class__c  = ' + student.Class__c );
            System.debug(logginglevel.INFO, '***** studentClass.My_Count__c   = ' + studentClass.My_Count__c  );
            studentClass.My_Count__c++;
            clsToBeUpdated.add(studentClass);
        }
        
    }
    update clsToBeUpdated ;
}